//
//  HMHospitalCollectionView.m
//  支付宝
//
//  Created by GD on 16/9/10.
//  Copyright © 2016年 HM. All rights reserved.
//

#import "HMHospitalCollectionView.h"
#import "ZFBMineOptionModel.h"
#import "ZFBMineLayout.h"
#import "HMTwoCellOneLineCell.h"
#import "HMOneSingleTurnCell.h"
#import "Addition.h"



static NSString *info_cell_ID = @"info_cell_ID";
static NSString *money_cell_ID = @"money_cell_ID";
static NSString *option_cell_ID = @"option_cell_ID";
static NSString *OneSingleCell = @"OneSingleCell";

static NSString *TwoCellOneLine = @"TwoCellOneLine";

@interface HMHospitalCollectionView ()<UICollectionViewDelegateFlowLayout,UICollectionViewDelegate,UICollectionViewDataSource>

@end

@implementation HMHospitalCollectionView
- (instancetype)initWithFrame:(CGRect)frame collectionViewLayout:(nonnull UICollectionViewLayout *)layout
{
    self = [super initWithFrame:frame collectionViewLayout:layout];
    if (self) {
        [self setUpUI];
    }
    return self;
}


//- (instancetype)init{
//    ZFBMineLayout *layout = [[ZFBMineLayout alloc]init];
//    //调用父类的initWithCollectionViewLayout方法。
//    //父类会根据我们传入的layout参数，创建一个和屏幕一样大小的collectionView
//    return [super initWithCollectionViewLayout:layout];
//}

-(void)setUpUI{
    self.contentInset = UIEdgeInsetsMake(10, 10, 0, 10);
    self.backgroundColor =[UIColor colorWithHex:0xf5f5f9]; //[UIColor colorWithHex:0xf5f5f9 alpha:1];
    
    self.delegate = self;
    self.dataSource = self;
    
    [self registerNib:[UINib nibWithNibName:@"TwoCellOneLine" bundle:nil] forCellWithReuseIdentifier:TwoCellOneLine];
    [self registerNib:[UINib nibWithNibName:@"OneSingleCell" bundle:nil] forCellWithReuseIdentifier:OneSingleCell];
    [self registerNib:[UINib nibWithNibName:@"ZFBOptionCell" bundle:nil] forCellWithReuseIdentifier:option_cell_ID];
}

#pragma mark -collectionView的数据源方法
- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView{
    return 3;
}
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
    switch (section) {
        case 0:
            return 2;
        case 1:
            return 1;
        case 2:
            return 6;
            //        case 3:
            //            return 6;
        default:
            return 0;
    }
}
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
    
    HMTwoCellOneLineCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:TwoCellOneLine forIndexPath:indexPath];
    if (indexPath.section == 0) {  //第0组
        //       HMTwoCellOneLineCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:TwoCellOneLine forIndexPath:indexPath];
        
        cell.model = self.twoInOneLieArray[indexPath.item];
        return cell;
    }
    
    if (indexPath.section == 1 && indexPath.item == 0) {  //第一组的第0个
        HMOneSingleTurnCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:OneSingleCell forIndexPath:indexPath];
        cell.backgroundColor = [UIColor whiteColor];
        
        cell.model = self.oneSingleArray[indexPath.item];
        
        
        return cell;
    }
    
    
    
    if (indexPath.section == 2) {
        HMTwoCellOneLineCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:option_cell_ID forIndexPath:indexPath];
        
        cell.model = self.bottemArray[indexPath.item];
        
        return cell;
    }
    
    return cell;
}

-(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{
    
    
    [self.subDelegate hospitalCollectionView:self didSelectIndexPath:indexPath];
}



#pragma mark -collectionViewDelegateFlowLayout方法
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath{
    if (indexPath.section == 0) {  //第0组
        return CGSizeMake((collectionView.bounds.size.width - 1 - 20) * 0.5, 100);
    }
    
    if (indexPath.section == 1 && indexPath.item == 0) {  //第一组的第0个
        return CGSizeMake(collectionView.bounds.size.width -20, 100);
    }
    
    CGFloat width = (collectionView.bounds.size.width - 1 -20) / 2;
    CGFloat height = 80;
    return CGSizeMake(width, height);
}



@end
